import { GSprite } from "../../../../com/mui/controls/GSprite";
import { TextBox } from "./TextBox";
import { UICompomentPool } from "../../../../com/mui/utils/UICompomentPool";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GameController } from "../../mvc/GameController";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SoundManager } from "../../../common/sound/SoundManager";
import { SoundTypeConst } from "../../../common/sound/SoundTypeConst";
import { Alert } from "../../../../com/mui/controls/Alert";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { MoneyUtil } from "../common/util/MoneyUtil";
import { GuideTipsManager } from "../../manager/GuideTipsManager";
import { Global } from "../../../../com/gengine/global/Global";
import { ParamsConst } from "../../../common/global/ParamsConst";
import { ProxyType } from "../../../common/global/ProxyType";
import { ImagesConst } from "../../resource/ImagesConst";
import { TimeButton } from "../common/button/TimeButton";
type int = number;
//class PackBottomPart
    
    export  class PackBottomPart extends GSprite
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */createTextBox(arg1: int, arg2: int): TextBox
        {
            var loc1=null;
            loc1 = UICompomentPool.getUICompoment(TextBox);
            loc1.createDisposedChildren();
            loc1.textFieldHeight = 18;
            loc1.textFieldWidth = 80;
            loc1.bgHeight = 18;
            loc1.bgWidth = 80;
            loc1.x = 29 + arg2 * 118;
            loc1.y = 4 + arg1 * 22;
            this.addChild(loc1);
            return loc1;
        }

        /* internal  */btnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GButton;
            var loc2=loc1;
            switch (loc2) 
            {
                case this._btnZhengli:
                {
                    if (GameController.trade.isInTrade()) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(40106));
                    }
                    else 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Tity));
                        SoundManager.instance.soundPlay(SoundTypeConst.BackpackFinishing);
                    }
                    break;
                }
                case this._btnHebing:
                {
                    Alert.show(Language.getString(40061), null, Alert.OK | Alert.CANCEL, null, this.onConfirmMerge);
                    break;
                }
                case this._btnBaitan:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.StallReady));
                    break;
                }
                case this._btnJishou:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MarketOpenSell));
                    break;
                }
            }
            return;
        }

        /* internal  */setTikyButton5s(): void
        {
            return;
        }

        /* internal  */createFairylandButton(): GLoadedButton
        {
            var loc1=ObjCreate.createGLoadedButton(ResFileConst.Fairyland, 15, 50, 52, 23, this);
            loc1.configEventListener(flash.events.MouseEvent.CLICK, this.onFairylandHandler);
            return loc1;
        }

        /* internal  */onConfirmMerge(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ButtomBtn_BackPack_Merge));
                this._btnHebing.trigger();
            }
            return;
        }

        /* internal  */onFairylandHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TreasureWarehourseModuleOpen));
            return;
        }

        /* internal  */createRechangeButton(): GLoadedButton
        {
            var loc1=ObjCreate.createGLoadedButton(ResFileConst.PackWallet, 230, 5, 36, 37, this);
            loc1.configEventListener(flash.events.MouseEvent.CLICK, this.onWalletHandler);
            return loc1;
        }

        /* internal  */createWardrobeButton(): GLoadedButton
        {
            var loc1=ObjCreate.createGLoadedButton(ResFileConst.PackWardrobe, 266, 6, 35, 36, this);
            loc1.configEventListener(flash.events.MouseEvent.CLICK, this.onWardrobeHandler);
            return loc1;
        }

        /* internal  */onWalletHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BackPackShowOrhideWallet));
            return;
        }

        /* internal  */onWardrobeHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.FashionBoxModuleShow));
            return;
        }

        public setCoinAmount(arg1: int): void
        {
            this._coinTextBox.htmlText = MoneyUtil.getCoinHtml(arg1);
            return;
        }

        public setCoinBindAmount(arg1: int): void
        {
            this._coinBindTextBox.htmlText = MoneyUtil.getCoinHtml(arg1);
            return;
        }

        public setGoldAmount(arg1: int): void
        {
            this._goldTextBox.htmlText = MoneyUtil.getGoldHtml(arg1);
            return;
        }

        public getWardrobeGlobalPosition(): Object /* flash.geom.Point */
        {
            return this.localToGlobal(new Object /* flash.geom.Point */(266, 6));
        }

        public wardrobeOpenGuide(): void
        {
            var loc1=GuideTipsManager.getGuideTips(GuideTipsManager.Dir_BL, Language.getString(90300), null, null, -1, -1, true, this.onClickTipsOpenWardrobe);
            loc1.x = 300;
            loc1.y = 6;
            addChild(loc1);
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            ObjCreate.disposeBitmap(this._bmpYuanbao, arg1);
            ObjCreate.disposeBitmap(this._bmpTongqian, arg1);
            ObjCreate.disposeBitmap(this._bmpYuanbaoBind, arg1);
            ObjCreate.disposeBitmap(this._bmpTongqianBind, arg1);
            this._goldTextBox.dispose(arg1);
            this._coinTextBox.dispose(arg1);
            this._goldBindTextBox.dispose(arg1);
            this._coinBindTextBox.dispose(arg1);
            this._btnJishou.dispose(arg1);
            if (Global.isDebugModle || ParamsConst.instance.proxyType == ProxyType.TW) 
            {
                if (this._btnBaitan) 
                {
                    this._btnBaitan.dispose(arg1);
                }
            }
            this._btnFairyland.dispose(arg1);
            this._btnRechange.dispose(arg1);
            this._btnWardrobe.dispose(arg1);
            super.disposeImpl(arg1);
            return;
        }

        /* internal  */onClickTipsOpenWardrobe(): void
        {
            this.hideWardrobeGuide();
            return;
        }

        public hideWardrobeGuide(): void
        {
            GuideTipsManager.hideGuideTips();
            Dispatcher.dispatchEvent(new DataEvent(EventName.WardrobeGuideOpen));
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            disposeChildren();
            super.dispose(arg1);
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            this._bmpYuanbao = ObjCreate.createBitmap(ImagesConst.Yuanbao, 5, 4, this);
            this._goldTextBox = this.createTextBox(0, 0);
            this._bmpTongqian = ObjCreate.createBitmap(ImagesConst.Tongqian, 5, 25, this);
            this._coinTextBox = this.createTextBox(1, 0);
            this._bmpYuanbaoBind = ObjCreate.createBitmap(ImagesConst.Yuanbao_bind, 120, 4, this);
            this._goldBindTextBox = this.createTextBox(0, 1);
            this._bmpTongqianBind = ObjCreate.createBitmap(ImagesConst.Tongqian_bind, 120, 25, this);
            this._coinBindTextBox = this.createTextBox(1, 1);
            var loc1=0;
            this._btnJishou = this.createButton(this.jishou, Language.getString(40056), loc1++);
            if (Global.isDebugModle || ParamsConst.instance.proxyType == ProxyType.TW) 
            {
                this._btnBaitan = this.createButton(this.baitan, Language.getString(40057), loc1++);
            }
            if (!this._btnHebing) 
            {
                this._btnHebing = this.createButton(this.hebing, Language.getString(40058), loc1++) as TimeButton;
                this._btnHebing.toolTipData = "<font color = \'#FFFFFF\'>" + Language.getString(40060) + "</font>";
            }
            this.addChild(this._btnHebing);
            if (!this._btnZhengli) 
            {
                this._btnZhengli = this.createButton(this.zhengli, Language.getString(40059), loc1++) as TimeButton;
            }
            this.addChild(this._btnZhengli);
            this._btnFairyland = this.createFairylandButton();
            this._btnRechange = this.createRechangeButton();
            this._btnWardrobe = this.createWardrobeButton();
            return;
        }

        public setGoldBindAmount(arg1: int): void
        {
            this._goldBindTextBox.htmlText = MoneyUtil.getGoldHtml(arg1);
            return;
        }

        public getBindGoldPoint(): Object /* flash.geom.Point */
        {
            return this.localToGlobal(new Object /* flash.geom.Point */(120, 4));
        }

        /* internal  */createButton(arg1: string, arg2: string, arg3: int): GButton
        {
            var loc1=null;
            if (!(arg1 == this.zhengli) && !(arg1 == this.hebing)) 
            {
                loc1 = UICompomentPool.getUICompoment(GButton);
            }
            else if (arg1 != this.zhengli) 
            {
                ((loc1 = UICompomentPool.getUICompoment(TimeButton) as TimeButton) as TimeButton).timeCount = 10;
                (loc1 as TimeButton).isClickTrigger = false;
            }
            else 
            {
                ((loc1 = UICompomentPool.getUICompoment(TimeButton) as TimeButton) as TimeButton).timeCount = 10;
            }
            loc1.name = arg1;
            loc1.label = arg2;
            loc1.width = 48;
            loc1.height = 22;
            var loc2=86;
            if (!Global.isDebugModle && !(ParamsConst.instance.proxyType == ProxyType.TW)) 
            {
                loc2 = 137;
            }
            loc1.x = loc2 + arg3 * 51;
            loc1.y = 50;
            loc1.styleName = "Button";
            loc1.configEventListener(flash.events.MouseEvent.CLICK, this.btnClickHandler);
            this.addChild(loc1);
            return loc1;
        }

        /* internal */ /* const */baitan: string="baitan";

        /* internal */ /* const */hebing: string="hebing";

        /* internal */ /* const */zhengli: string="zhengli";

        /* internal */ /* const */jishou: string="jishou";

        /* internal */ /* var */_bmpYuanbao: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpTongqian: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpYuanbaoBind: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpTongqianBind: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_coinTextBox: TextBox;

        /* internal */ /* var */_goldBindTextBox: TextBox;

        /* internal */ /* var */_coinBindTextBox: TextBox;

        /* internal */ /* var */_btnJishou: GButton;

        /* internal */ /* var */_btnBaitan: GButton;

        /* internal */ /* var */_btnHebing: TimeButton;

        /* internal */ /* var */_btnZhengli: TimeButton;

        /* internal */ /* var */_btnFairyland: GLoadedButton;

        /* internal */ /* var */_btnRechange: GLoadedButton;

        /* internal */ /* var */_btnWardrobe: GLoadedButton;

        /* internal */ /* var */_goldTextBox: TextBox;
    }
